import Vue from "vue";
import {actions} from '../base';

let url = 'admin/api/app-source-cpa';

export default {
    namespaced: true,
    state: {
        all: [],
        configs: {
            kuaishou: {},
        },
        options: {
            channels: {
                kuaishou: {label: '快手 - 磁力引擎', value: "kuaishou"},
                douyin: {label: '抖音 - 巨量引擎', value: "douyin"},
                baidu: {label: '百度 - 百度营销', value: "baidu"},
                tencent: {label: '腾讯 - 腾讯广告', value: "tencent"},
                uc: {label: 'UC - UC搜索', value: "uc"},
                custom: {label: '自定 - 公式计算', value: "custom"},
            }
        },
        request: {
            all: false,
        }
    },
    mutations: {
        SET_ALL(state, data) {
            state.all = data;
        },
        SET_REQUESTING(state, name) {
            state.request[name] = true;
        },
        SET_REQUESTED(state, name) {
            state.request[name] = false;
        },
        SET_CONFIGS(state, data) {
            state.configs = data;
        },
    },
    actions: Object.assign(actions(url), {
        GetConfigs({commit}) {
            return new Promise((resolve, reject) => {
                Vue.axios.get(`${url}/configs`).then(res => {
                    commit('SET_CONFIGS', res.data);
                    return resolve(res);
                }).catch(error => {
                    return reject(error);
                });
            });
        },
        GetDayCpaCost({commit}, filter = {}) {
            return Vue.axios.get(`${url}/day-cpa-cost`, {
                params: filter,
            })
        }
    }),
};
